import time

from selenium.webdriver.common.by import By

from Base.BasePage import BasePage


class ReviewAplay(BasePage):
    def __init__(self, driver):
        super().__init__(driver)
        self.driver = driver
    #     借款管理
        self.borrowing_management = (By.XPATH, '/html/body/div[1]/div[2]/ul/li[2]/a')
    #     额度管理
        self.quota_management = (By.XPATH, '//*[@id="sidebar"]/ul/li[5]/a/span')
    #     额度申请
        self.aplay = (By.XPATH, '//*[@id="sidebar"]/ul/li[5]/ul/li[2]/a')
    #     输入用户名
        self.username = (By.XPATH, '/html/body/div[2]/div[1]/div/ul/li[1]/div/input')
    #     点击搜索
        self.search = (By.XPATH, '/html/body/div[2]/div[1]/div/ul/li[3]/input')
#         iframe
        self.iframe1 = (By.ID, 'iframe_box')
# #         选择记录
        self.select_record = (By.XPATH, '/html/body/div[2]/div[3]/table/tbody/tr[1]')
# #         审核按钮
        self.review = (By.XPATH, '/html/body/div[2]/div[2]/ul/li[1]/a')
#           iframe2
        self.iframe2 = (By.CSS_SELECTOR,".xubox_iframe")
#         通过
        self.pass_review = (By.XPATH, '/html/body/div[2]/form/table/tbody/tr[5]/td[2]/div/label[1]/input')
#         不通过
        self.fail_review = (By.XPATH, '/html/body/div[2]/form/table/tbody/tr[5]/td[2]/div/label[2]/span')
#         审核备注
        self.remark = (By.XPATH, '/html/body/div[2]/form/table/tbody/tr[6]/td[2]/div/textarea')
#         验证码
        self.verifycode = (By.XPATH, '/html/body/div[2]/form/table/tbody/tr[7]/td[2]/div/ul/li[1]/input')
#         点击保存
        self.save = (By.XPATH, '/html/body/div[2]/form/table/tbody/tr[8]/td[2]/input[1]')
#          断言
        self.assert_review_aplay = (By.CSS_SELECTOR,".xubox_msg.xubox_text")
# 定义方法
    def review_aplay_serch(self, username):
        """
        额度申请审核
        :param username:
        :return:
        """
        self.click_element(self.borrowing_management)
        self.click_element(self.quota_management)
        time.sleep(2)
        self.click_element(self.aplay)
        self.switch_frame(self.iframe1)
        self.base_clear_input(self.username, username)
        self.click_element(self.search)

    def review_aplay_pass(self, remark, verifycode):
        time.sleep(2)
        self.click_element(self.select_record)
        self.click_element(self.review)
        self.switch_frame(self.iframe2)
        self.click_element(self.pass_review)
        self.base_clear_input(self.remark, remark)
        self.base_clear_input(self.verifycode, verifycode)
        self.click_element(self.save)

    def assert_review_aplay_pass(self):
        result = self.get_element(self.assert_review_aplay).text
        return result
